'use strict';

app.controller('interest_detail_Ctrl', ['$scope','$http','loginService','$routeParams','adminService', function($scope,$http,loginService,$routeParams,adminService){
	
	 $scope.init = function() {
		     loginService.lock_admin(); 
			 $scope.link = loginService.getLink();
	    	 if($routeParams.id==0){
				$scope.text = "Create an interest";
				$scope.status=1;
				$scope.role=2;
			 }
		     else{
				 $scope.text = "Update interest";
				 //$scope.interest = $routeParams.id;
				 $scope.getByInterestId($routeParams.id);
			 }
				 
	    };
	
	
	 $scope.getByInterestId = function(id){ 
	        $http.get($scope.link+'interest_/'+id).success(function(data){ 
	        	console.log('an interest is loaded');
	        	$scope.interest = data.data.name;
				$scope.id = data.data.id;
	        }).error(function(data, status, config) { alert('no');
	        	console.log('can not load interest with interest id : ' + id);
	 });
	 }
	
	 $scope.submit = function() {
		     	if($routeParams.id==0)
				{
				  $scope.id = 0;
				}	
				var user = loginService.getUser();
				$scope.username = user.username;
				$scope.password = user.password;
				adminService.submit_interest($scope.username,$scope.password,$scope.interest,$routeParams.id);	
				
	    };
	
}])